function Attachment_Self_list() {
    var _this = this;
    var page;
    _this.obj = null;
    _this.templateArr = [];
    _this.page_size = 10;
    var courseId = $("#courseId").val();
    var chrStatus = $("#chrStatus").val();
    // init
    _this.init = function(_page) {
        page = _page;
        _this.updateAttachmentCount();
        _this.initTable();
        _this.initEvent();
    }
    // 更新课程下的课件数量
    _this.updateAttachmentCount = function () {
        $.ajax({
            url: appPath+"/admin/exCourseSelf/updateAttachmentCount",
            data: {
                "courseId":$("#courseId").val()
            },
            dataType: "json",
            async: true,
            type: "POST",
            success: function (data) {

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg(textStatus,{icon:2});
            }
        });

    };

    _this.initTable = function() {
        var list_url = appPath + "/admin/attachmentSelf/list";
        page.init("attachment_self_form", list_url, "attachment_self_list", "attachment_self_page", 1, _this.page_size);
        page.goPage(1);
        page.list = function(dataList){
            _this.obj = dataList;
            if(dataList == null){
                return;
            }
            var len = dataList.length;
            var inner = "", item;
            var viewStatus = "";
            // 组装数据
            for(var i=0; i< len; i++) {
                item = dataList[i];
                inner += '<tr >';
                inner += '<td width="50">' + (i+1) + '</td>';
                inner += '<td width="50"><input type=\"checkbox\" name="courseBox" data-id="' + item['intId'] + '">';
                inner += '<input type=\"hidden\"  value="' + item['varFid'] + '"></td>';
                inner += '<td >'+ item['intId'] + '</td>';
                inner += '<td >'+ item['varLocalName'] + '</td>';
                inner += '<td >'+ item['varType'] + '</td>';
                inner += '<td>'+ item['datCreateDate'].substr(0,19) + '</td>';
              //inner += '<td width="100">'+ TimeUtil.getHouAndMinAndSec(item['class_hour']*60) + '</td>';
              //   viewStatus = item['viewStatus'] == "0" ? "未查看":"已查看";
              //   inner += '<td>'+ viewStatus + '</td>';
                inner += '<td >';
                if(i != 0 && chrStatus == '1'){
                    inner += '<a href="javascript:attachment_self_list.move(\''+ item['intId'] +'\',\'top\');" class="a a-publish">置顶</a> ';
                    inner += '<a href="javascript:attachment_self_list.move(\''+ item['intId'] +'\',\'up\');" class="a a-info">上移</a> ';
                }
                if(i != len -1 && chrStatus == '1'){
                    inner += '<a href="javascript:attachment_self_list.move(\''+ item['intId'] +'\',\'down\');" class="a a-publish">下移</a> ';
                }
                inner += '<a href="javascript:attachment_self_list.delete(\''+ item['intId'] +'\');" class="a a-close">删除</a> ';
                inner += '</td></tr>';
            }
            return inner;
        }

    };

    //移动(上移下移置顶)
    _this.move = function (intid, moveType) {
        $.ajax({
            url: appPath + "/admin/attachmentSelf/move",
            data: {
                "courseId":courseId,
                "attachmentId":intid,
                "moveType":moveType
            },
            dataType: "json",
            async: true,
            type: "POST",
            success: function (data) {
                var code = eval(data).code;
                var message = eval(data).message;
                if (code == 10000 ) {
                    layer.msg(message) ;
                    // 更新列表
                    _this.initTable();
                } else {
                    layer.msg(message, {icon: 2}) ;
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg(textStatus,{icon: 2}) ;
            }
        });
    };

    _this.initEvent = function () {


    }
    // 批量删除
    _this.deleteMany = function () {
        var checkeds = $('#attachment_self_list').find(" input[type=checkbox]:checked");
        if(checkeds.length <= 0) {
            layer.msg("请选择至少一行数据！",{icon:7});
            return;
        }

        var attachmentIds = [];
        $(checkeds).each(function() {
            attachmentIds.push($(this).attr("data-id"));
        });
        // 删除课件
        _this.deleteAttachment(attachmentIds);
    };

    //单个删除
    _this.delete = function (intId) {
        var attachmentIds = [intId];
        _this.deleteAttachment(attachmentIds);
    }

    //删除
    _this.deleteAttachment = function (attachmentIds) {
        layer.confirm('确定删除当前所选数据？', {btn: ['是','否']}, function(index){
            //删除
            layer.close(index);
            $.ajax({
                url: appPath + "/admin/attachmentSelf/delete",
                data: {
                    "courseId":courseId,
                    "chrStatus":chrStatus,
                    "attachmentIds":attachmentIds.join(","),
                    "companyId":$("#companyId").val()
                },
                dataType: "json",
                async: true,
                type: "POST",
                success: function (data) {
                    var result = eval(data).result;
                    var count = eval(data).count;
                    if (result == "success" ) {
                        if("0" == count){

                            layer.msg("删除成功",{icon: 1});
                        }else{
                            var tipMsg = "删除失败!";
                            tipMsg += "\n 该课程已被项目引用，不允许删除" ;
                            layer.msg(tipMsg) ;
                        }

                        // 更新列表
                        _this.initTable();
                    } else {
                        var tipMsg = "删除失败!";
                        var error = eval(data).errorMsg;
                        if(error != null && error != "") {
                            tipMsg += "\n" + error;
                        }
                        layer.msg(tipMsg,{icon: 2}) ;
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg(textStatus,{icon: 2}) ;
                }
            });
        });
    }

    // 弹出课件上传模态框
    _this.attachment_add = function () {
        if(chrStatus===3||chrStatus==='3'){
            return;
        }
        layer.open({
            type:2,
            title: "添加课件（支持格式包括:mp3,mp4,flv,doc,docx,ppt,pptx,pdf,xls,xlsx,swf）",
            closeBtn: false,
            area: ['1000px', '400px'], // 弹出层大小
            scrollbar: false,	//false隐藏滑动块
            btn:['保存','取消'],
            content: [appPath + '/admin/questionSelf/upload' , 'yes'],
            btn1: function(index, layero) {
                layer.close(index);
                var fileList = layero.find("iframe")[0].contentWindow.$("#fileList").val();
                _this.saveAttachment(fileList);
            },
            btn2: function(index) {
                layer.close(index);
            }
        });
    };


    _this.forback = function(){
        window.opener.course_self_list.search();
        window.close();
    };


    // 保存上传的课件
    _this.saveAttachment = function (fileList) {
        // var fileList = $("#fileList").val();
        if("" == fileList || fileList == "undefined"){
            layer.msg("请先上传课件后保存！",{icon:7});
            return;
        }
        var param = {
            "fileList":fileList,
            "courseId":courseId,
            "chrStatus":chrStatus
        }
        $.ajax({
            url: appPath + "/admin/attachmentSelf/save_attachment",
            data: param,
            dataType: "json",
            async: true,
            type: "POST",
            success: function (data) {
                var result = eval(data).result;
                if (result == "success") {
                    layer.msg("保存成功",{icon:1});
                    _this.initTable();
                } else {
                    var tipMsg = "保存失败!";
                    var error = eval(data).errorMsg;
                    if(error != null && error != "") {
                        tipMsg += "\n" + error;
                    }
                    layer.msg(tipMsg,{icon:2});
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                Metronic.unblockUI('#orgDetailPane');
                layer.msg("保存失败",{icon:2});
            }
        });
    };



}

var attachment_self_list = new Attachment_Self_list();


//搜索高亮
function getFontCss(treeId, treeNode){
    return (!!treeNode.highlight)?{'color': "#A60000", 'font-weight':"bold"}:{'color': "#333", 'font-weight':"normal"};
}